from flask import Flask, jsonify, abort, request
from flask_restful import Api, Resource
from draw import Draw
app = Flask(__name__)
api = Api(app)


class HelloWorld(Resource):
    def get(self):
        return {'hello': 'world'}


class WriteDXF(Resource):

    def post(self):
        if not request.json or not 'fileName' in request.json:
            abort(400)
        fileName = request.json.get('fileName', '')
        contents = request.json.get('contents', '')
        d = Draw()
        # draw
        dxfFile = d.drawDxf(fileName, contents)
        return dxfFile, 200


api.add_resource(HelloWorld, '/')
api.add_resource(WriteDXF, '/api/writedxf')

if __name__ == "__main__":
    app.run(debug=True, port=5000)
